package org.gvp.record.controller;

import lombok.RequiredArgsConstructor;

import org.gvp.common.constant.SummerController;
import org.gvp.record.dto.ItemDTO;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import org.gvp.common.constant.BaseController;
import org.gvp.common.annotation.Operation;
import org.gvp.common.http.Page;
import org.gvp.common.http.Result;
import org.gvp.record.service.ReportDetailService;
import org.gvp.record.pojo.ReportDetail;
import java.util.List;

@RestController
@RequestMapping("/record/report/detail")
@RequiredArgsConstructor
public class ReportDetailController implements SummerController<ReportDetail> {
    private final ReportDetailService reportDetailService;

    @Operation(value = "更新报销项目", param = "报销项目对象")
    @PostMapping("/item")
    public boolean updateItem(@RequestBody ItemDTO dto){
        return this.reportDetailService.editItem(dto);
    }

    @Operation(value = "添加报销项目", param = "报销项目对象")
    @PutMapping("/item")
    public boolean addItem(@RequestBody ItemDTO dto){
        return this.reportDetailService.saveItem(dto);
    }

    @Operation(value = "删除报销选项", param = "报销选项的key")
    @DeleteMapping("/item/{key}")
    public boolean deleteItem(@PathVariable String key){
        return this.reportDetailService.removeItem(key);
    }

    @Operation("获取全部的报销项列表")
    @GetMapping("/item")
    public List<ItemDTO> queryItemList(){
        return this.reportDetailService.findItemList();
    }

    @PutMapping
    @Override
    public Integer add(@RequestBody ReportDetail dto) {
        return reportDetailService.save(dto);
    }

    @Operation(value = "添加报销记录并且反回新的报销记录", param = "报销记录对象")
    @PutMapping("/return")
    @Override
    public ReportDetail addReturn(@RequestBody ReportDetail dto) {
        return reportDetailService.saveAndReturn(dto);
    }

    @PostMapping
    @Override
    public Integer update(@RequestBody ReportDetail dto) {
        return reportDetailService.edit(dto);
    }


    @Operation(value = "根据报销单编号查找报销记录列表", param = "报销单编号")
    @GetMapping("/list/{reportId:\\d+}")
    public List<ReportDetail> queryListByReportId(@PathVariable Integer reportId) {
        return this.reportDetailService.findListByReportId(reportId);
    }

    @Operation(value = "根据报销单编号查找报销单详细信息分页数据", param = "reportId:报销单编号,page:当前页,size:页大小")
    @GetMapping("/page/{reportId:\\d+}/{page:\\d+}/{size:\\d+}")
    public Page<ReportDetail> queryPageByReportId(@PathVariable Integer reportId,@PathVariable int page,@PathVariable int size) {
        return reportDetailService.findPageByReportId(reportId,page,size);
    }

}
